<?php 

namespace pmvc\mvc\security;

use pmvc\mvc\Request;

class SecurityUtil {

	const PMVC_SESSION_USER	= "__pmvc_security_User";

	public static function setCurrentUser(Request $request, User $user) {
		if ($user==NULL) {
			self::clear($request);
		} else {
			$request->setSessionVariable(self::PMVC_SESSION_USER, $user);
		}
	}

	public static function getCurrentUser(Request $request) {
		return ($request->hasSessionVariable(self::PMVC_SESSION_USER))
			? $request->getSessionVariable(self::PMVC_SESSION_USER)
			: NULL;
	}

	public static function isLoggedIn(Request $request) {
		return $request->hasSessionVariable(self::PMVC_SESSION_USER);
	}

	public static function clear(Request $request) {
		$request->removeSessionVariable(self::PMVC_SESSION_USER);
	}

}

?>